package com.easy.controllor;

import com.easy.bean.User;
import com.easy.service.RegisterService;
import com.easy.service.UserService;
import com.easy.util.CaptchaUtil;
import com.easy.util.Result;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.AccessType;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/register")
public class RegistorControllor {

    @Autowired
    RegisterService registerService;

    @PostMapping("/doregister")
    public Result registor(User user, @RequestParam("captcha")String captcha, @RequestParam("key")String key) {
        System.out.println("User："+user+"captcha："+captcha+"key："+key);
        //验证码验证
        if(!CaptchaUtil.checkCaptcha(key,captcha)){
            return Result.fail(500,"验证码错误");
        }
        String token = registerService.register(user);
        return Result.success("注册成功", token);
    }


}
